import http from '@/utils/request'

/**
 * 获取结算的信息(预生成订单的数据)
 */
export const getCheckoutInfo = () => {
    return http('/member/order/pre', 'get')
}

/**
 * 添加收货地址信息
 * @param {Object} address - 地址对象
 */
export const addAddressApi = address => {
    return http('/member/address', 'post', address)
}

/**
 * 编辑收货地址信息
 * @param {Object} address - 地址对象
 */
export const editAddressApi = address => {
    return http('/member/address/' + address.id, 'put', address)
}

/**
 * 提交订单
 * @param {Object} order - 订单信息对象
 */
export const createOrderApi = order => {
    return http('/member/order', 'post', order)
}

/**
 * 获取订单详情
 * @param {String} id - 订单ID
 */
export const findOrderDetailApi = id => {
    return http('/member/order/' + id, 'get')
}

/**
 * 获取我的收藏
 * @param {Number} page 页码
 * @param {Number} pageSize 每页显示的条数
 * @param {Number} collectType 收藏类型，1为商品，2为专题，3为品牌
 * @returns
 */

export const getCollect = (page = 1, pageSize = 4, collectType = 1) => {
    // Mock有一个拦截axios的作用，肯定优先匹配mock中的api,如果mock中没有，就请求真实的api
    return http('/member/collect', 'get', {
        page,
        pageSize,
        collectType
    })
}

/**
 * 获取我的足迹
 * @param {Number} page 页码
 * @param {Number} pageSize 每页显示的条数
 * @returns
 */

export const getBrowseHistory = (page = 1, pageSize = 4) => {
    return http('/member/browseHistory', 'get', {
        page,
        pageSize
    })
}

/**
 * 查询订单列表
 * @param {Number} orderState - 订单状态，1为待付款、2为待发货、3为待收货、4为待评价、5为已完成、6为已取消，未传该参数或0为全部
 * @param {Number} page - 页码
 * @param {Number} pageSize - 每页条数
 * @returns
 */
export const orderListApi = ({
    orderState,
    page,
    pageSize
}) => {
    return http('/member/order', 'get', {
        orderState,
        page,
        pageSize
    })
}

/**
 * 取消订单
 * @param {String} orderId - 订单ID
 * @param {String} cancelReason - 取消原因
 * @returns Promise
 */
export const cancelOrderApi = (orderId, cancelReason) => {
    return http(`/member/order/${orderId}/cancel`, 'put', {
        cancelReason
    })
}

/**
 * 删除订单
 * @param {Array<string>} ids - 删除订单，id集合
 * @returns
 */
export const delteOrderApi = (ids) => {
    return http('/member/order', 'delete', {
        ids
    })
}

/**
 *  确认收货
 * @param {String} orderId 订单id
 * @returns
 */
export const receiptOrderApi = orderId => {
    return http(`/member/order/${orderId}/receipt`, 'put')
}

/**
 * 查看物理
 * @param {String} id - 订单ID
 * @returns
 */
export const logisticsOrderApi = id => {
    return http(`/member/order/${id}/logistics`, 'get')
}

/**
 * 获取再次购买的订单结算信息
 * @param {String} id - 订单ID
 * @returns
 */
export const findOrderRepurchaseApi = (id) => {
    return http(`/member/order/repurchase/${id}`, 'get')
}